﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Security;
using Apodidae.Common;
using Apodidae.Core.Dao;
using Apodidae.Domain.Entity;
using ComDevFx.Arch.Base.Persister;

namespace Apodidae.Core.Imp
{
    public class ClassService : ServiceBase, IClassService
    {
        private ClassInfoDao _classInfoDao;
        private GroupInfoDao _groupInfoDao;

        protected override void PrepareInternal()
        {
            _classInfoDao = new ClassInfoDao();
            _groupInfoDao = new GroupInfoDao();
        }

        #region 班级操作相关

        public ClassInfo GetClassInfo(object id, GetType action)
        {
            if (action == ComDevFx.Arch.Base.Persister.GetType.Get)
            {
                return _classInfoDao.Get(id);
            }
            else
            {
                try
                {
                    _classInfoDao.Load(id);
                }
                catch
                {
                    return null;
                }
            }
            return null;
        }

        public IList<ClassInfo> GetClassInfosByTeacherId(string teacherId)
        {
            return _classInfoDao.Query(string.Format("where this.TeacherId='{0}'", teacherId));
        }


        #region CURD UserInfo

        public ClassInfo Save(ClassInfo entity)
        {
            return _classInfoDao.Save(entity) as ClassInfo;
        }
        public void SaveOrUpdate(ClassInfo entity)
        {
            _classInfoDao.SaveOrUpdate(entity);
        }
        public void Delete(ClassInfo entity)
        {
            _classInfoDao.Delete(entity);
        }

        #endregion

        #endregion

        #region 小组操作相关

        public GroupInfo GetGroupInfo(object id, GetType action)
        {
            if (action == ComDevFx.Arch.Base.Persister.GetType.Get)
            {
                return _groupInfoDao.Get(id);
            }
            else
            {
                try
                {
                    return _groupInfoDao.Load(id);
                }
                catch
                {
                    return null;
                }
            }
            return null;
        }

        #region CURD GroupInfo

        public GroupInfo Save(GroupInfo entity)
        {
            return _groupInfoDao.Save(entity) as GroupInfo;
        }
        public void SaveOrUpdate(GroupInfo entity)
        {
            _groupInfoDao.SaveOrUpdate(entity);
        }
        public void Delete(GroupInfo entity)
        {
            _groupInfoDao.Delete(entity);
        }

        #endregion

        #endregion

    }
}
